package GUI;

import Logica.Treatment1;

import java.awt.Color;
import java.awt.Dimension;

import java.awt.Font;
import java.awt.Rectangle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class AgregarT1 extends JFrame {
  private JLabel jlabelAgregarT = new JLabel();
  private JLabel des = new JLabel();
  private JLabel cos = new JLabel();
  private JLabel cant = new JLabel();
  private JLabel obs = new JLabel();
  private JLabel bd = new JLabel();
  private JLabel ed = new JLabel();
  private JLabel numExa = new JLabel();
  private JButton jButtonGuardarTre = new JButton();
  private JFormattedTextField jFormDescri = new JFormattedTextField();
  private JFormattedTextField jFormCost = new JFormattedTextField();
  private JFormattedTextField jFormCant = new JFormattedTextField();
  private JFormattedTextField jFormObs = new JFormattedTextField();
  private JFormattedTextField jFormFechaIn = new JFormattedTextField();
  private JFormattedTextField jFormFechaFin = new JFormattedTextField();
  private JFormattedTextField jFormNoExa = new JFormattedTextField();
  private JLabel jLabelPonerFecha1 = new JLabel();
  private JLabel jLabelPonerFecha2 = new JLabel();

  Treatment1 trea = new Treatment1();

  public AgregarT1() {
    try {
      jbInit();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    this.getContentPane().setLayout(null);
    this.setSize(new Dimension(528, 575));
    this.setTitle("Agregar Tratamiento");
    this.setFont(new Font("Dialog", 0, 20));
    jlabelAgregarT.setText("AGREGAR TRATAMIENTO");
    jlabelAgregarT.setBounds(new Rectangle(125, 15, 245, 50));
    jlabelAgregarT.setFont(new Font("Tahoma", 0, 20));
    jlabelAgregarT.setForeground(new Color(15, 9, 189));
    des.setText("Descripcion");
    des.setBounds(new Rectangle(20, 115, 160, 40));
    des.setFont(new Font("Tahoma", 0, 14));
    cos.setText("Costo");
    cos.setBounds(new Rectangle(20, 160, 160, 40));
    cos.setFont(new Font("Tahoma", 0, 14));
    cant.setText("Cantidad");
    cant.setBounds(new Rectangle(15, 215, 105, 40));
    cant.setFont(new Font("Tahoma", 0, 14));
    obs.setText("Observaciones");
    obs.setBounds(new Rectangle(10, 265, 160, 40));
    obs.setFont(new Font("Tahoma", 0, 14));
    bd.setText("Fecha Inicio");
    bd.setBounds(new Rectangle(15, 320, 95, 40));
    bd.setFont(new Font("Tahoma", 0, 14));
    ed.setText("Fecha Final");
    ed.setBounds(new Rectangle(20, 375, 160, 40));
    ed.setFont(new Font("Tahoma", 0, 14));
    numExa.setText("No. Examen");
    numExa.setBounds(new Rectangle(10, 435, 100, 40));
    numExa.setFont(new Font("Tahoma", 0, 14));
    jButtonGuardarTre.setText("GUARDAR");
    jButtonGuardarTre.setBounds(new Rectangle(375, 495, 130, 40));
    jButtonGuardarTre.setFont(new Font("Arial Black", 0, 11));
    jButtonGuardarTre.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          jButton1_actionPerformed(e);
        }
      });
    jFormDescri.setBounds(new Rectangle(120, 120, 270, 40));
    jFormCost.setBounds(new Rectangle(120, 170, 270, 35));
    jFormCant.setBounds(new Rectangle(120, 220, 270, 35));
    jFormObs.setBounds(new Rectangle(120, 270, 270, 35));
    jFormFechaIn.setBounds(new Rectangle(120, 325, 270, 35));
    jFormFechaFin.setBounds(new Rectangle(120, 380, 270, 35));
    jFormNoExa.setBounds(new Rectangle(120, 440, 270, 35));
    jLabelPonerFecha1.setText("yyyy-mm-dd");
    jLabelPonerFecha1.setBounds(new Rectangle(405, 325, 105, 35));
    jLabelPonerFecha2.setText("yyyy-mm-dd");
    jLabelPonerFecha2.setBounds(new Rectangle(400, 380, 105, 35));

    this.getContentPane().add(jLabelPonerFecha2, null);
    this.getContentPane().add(jLabelPonerFecha1, null);
    this.getContentPane().add(jFormNoExa, null);
    this.getContentPane().add(jFormFechaFin, null);
    this.getContentPane().add(jFormFechaIn, null);
    this.getContentPane().add(jFormObs, null);
    this.getContentPane().add(jFormCant, null);
    this.getContentPane().add(jFormCost, null);
    this.getContentPane().add(jFormDescri, null);
    this.getContentPane().add(jButtonGuardarTre, null);
    this.getContentPane().add(numExa, null);
    this.getContentPane().add(ed, null);
    this.getContentPane().add(bd, null);
    this.getContentPane().add(obs, null);
    this.getContentPane().add(cant, null);
    this.getContentPane().add(cos, null);
    this.getContentPane().add(des, null);
    this.getContentPane().add(jlabelAgregarT, null);


  }

  private void jButton1_actionPerformed(ActionEvent e) {
  
    String NumExa = this.jFormNoExa.getText().toString();
    System.out.println(NumExa);
    String Cant = this.jFormCant.getText().toString();
    System.out.println(Cant);
    String cost = this.jFormCost.getText().toString();
    System.out.println(cost);
    String Des = this.jFormDescri.getText().toString();
    System.out.println(Des);
    String FechaFin = this.jFormFechaFin.getText().toString();
    System.out.println(FechaFin);
    String FechaIn = this.jFormFechaIn.getText().toString();
    System.out.println(FechaIn);
    String Obs = this.jFormObs.getText().toString();
    System.out.println(Obs);
    if (trea.creaTratamiento(Des, cost, Cant, Obs, FechaIn, FechaFin,
                             NumExa)) {
      JOptionPane.showMessageDialog(null, "Creado",
                                    "El tratamiento ha sido creado",
                                    JOptionPane.INFORMATION_MESSAGE);
    }
    else{
      JOptionPane.showMessageDialog(null, "No Creado",
                                    "El tratamiento no ha sido creado",
                                    JOptionPane.ERROR_MESSAGE);
    }

  }
  

}

